/*
 * mhdirscanner.cpp
 *
 *  Created on: 2010-8-24
 *      Author: angelstone
 */
#include <wx/wx.h>
#include <wx/dir.h>

#include "mhfilescanner.h"
#include "mhmedia.h"

using namespace mediahouse;

int CMHFileScanner::CanScanPath(CMHContext * pContext,
		const wxString & strMediaPath, void * cookies) {
	return wxFileExists(strMediaPath) ? 1 : 0;
}

int CMHFileScanner::ScanPath(CMHContext * pContext,
		const wxString & strMediaPath, void * cookies) {

	if (!CanScanPath(pContext, strMediaPath, cookies))
		return 0;

	hiberlite::bean_ptr<mediahouse::CMHMedia> file;
	wxDateTime modifyTime(wxFileModificationTime(strMediaPath));

	if (pContext->FindMediaByLocation(strMediaPath, file)) {
		if (file->GetModified() >= modifyTime)
			return 0;
	} else {
		file = pContext->GetDatabase()->createBean<mediahouse::CMHMedia>();
		file->SetLocation(strMediaPath);
		file.save();
	}

	//Do not update file modify time here, let media addon to update the modify time.
	return pContext->HandleMedia(file, cookies);
}
